package com.akk.utils;

import org.junit.Test;

import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * @company www.lovekaka.com
 * @auther hainlc
 * @create 2017/06/16 14:14
 */
public class IDUtils {

    private static final Random _Rand = new Random();
    private static final char[] _number = ("0123456789").toCharArray();

    public static final String getPK() {
        return UUID.randomUUID().toString().replace("-","");
    }

    /**
     * 生成14位订单号
     * 根据等级规则
     * @return
     */
    public static final String getUniqueNum14()
    {
        String monthStr = (char)(Integer.valueOf(DateUtils.formatGetMonth(new Date()))+ 65)+"";
        String dayStr = (char)(Integer.valueOf(DateUtils.formatByPatt(new Date(),"H"))+ 65)+"";
        int num = (int)(Math.random()*100000);
        long time = System.currentTimeMillis();
        return monthStr+dayStr+String.valueOf(time).substring(4)+num;
    }


    /**
     * 图片名生成
     */
    public static String genImageName() {
        //取当前时间的长整形值包含毫秒
        long millis = System.currentTimeMillis();
        //long millis = System.nanoTime();
        //加上三位随机数
        Random random = new Random();
        int end3 = random.nextInt(999);
        //如果不足三位前面补0
        String str = millis + String.format("%03d", end3);
        return str;
    }

    /**
     * id生成
     */
    public static long generateId() {
        //取当前时间的长整形值包含毫秒
        long millis = System.currentTimeMillis();
        //long millis = System.nanoTime();
        System.out.println(millis);
        //加上两位随机数
        Random random = new Random();
        int end4 = random.nextInt(9999);
        //如果不足两位前面补0
        String str = millis + String.format("%04d", end4);
        long id = new Long(str);
        return id;
    }


    @Test
    public void testUnique14(){
        System.out.println(getUniqueNum14());
    }

    @Test
    public void  testPk(){
        System.out.println(getPK());
    }
}